﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace TonyNet4V1.ShowLayer
{
	public class AddViewBase : System.Web.UI.Page
	{
		#region 属性
		private string strTotal = "";
		
		Panel pContent = new Panel();
		protected FormView clsView;
		protected Panel pOperation = new Panel();
		protected Button btnOperation = new Button();
		#endregion 属性

		public AddViewBase(string strTotal)
		{
			this.strTotal = strTotal;

			clsView = new FormView(Page);

			btnOperation.ID = "201408231701";
			btnOperation.CommandName = "201408231702";
			btnOperation.Text = "添加";
		}

		protected override void OnInit(EventArgs e)
		{
			clsView.clsPage = Page;

			base.OnInit(e);

			clsView.Init();

			Layout();
			SetControlCSS();
			ControlEvent();
			ShowDefault();
		}

		protected virtual void Layout()
		{
			LayoutContent(pContent);
			//pTotal.Controls.Add(pContent);
			Page.FindControl(strTotal).Controls.Add(pContent);

			pOperation.Controls.Add(btnOperation);
			//pTotal.Controls.Add(pOperation);
			Page.FindControl(strTotal).Controls.Add(pOperation);
		}

		protected virtual void LayoutContent(Panel pPanel)
		{
			clsView.AddEditLayout(pPanel);
		}
		/// <summary>
		/// 设置控件CSS值
		/// </summary>
		protected virtual void SetControlCSS()
		{
		}
		/// <summary>
		/// 设置控件事件响应函数
		/// </summary>
		protected virtual void ControlEvent()
		{
			btnOperation.Click += new EventHandler(btnOperation_Click);
		}

		void btnOperation_Click(object sender, EventArgs e)
		{
			Operation();
		}

		/// <summary>
		/// 默认状态
		/// </summary>
		protected virtual void ShowDefault()
		{
			clsView.ShowAdd();
		}

		/// <summary>
		/// 操作
		/// </summary>
		protected virtual void Operation()
		{
			clsView.Add();
		}
	}
}
